Skip to content

MkProgressBar

:fa-brands-github: Show source on GitHub

Node to display a CSS-based progress bar.

Example: Regular

Jinja

{{ 60 | MkProgressBar }}

Python

MkProgressBar(60)

60%

[=60% "60%"]
<p>
<div class="progress progress-60plus">
<div class="progress-bar" style="width:60.00%">
<p class="progress-label">60%</p>
</div>
</div>
</p>
`██████░░░░` 60%

Example: Style thin

Jinja

{{ 60 | MkProgressBar(style="thin") }}

Python

MkProgressBar(60, style='thin')

60%

[=60% "60%"]{: .thin}
<p>
<div class="progress progress-60plus thin">
<div class="progress-bar" style="width:60.00%">
<p class="progress-label">60%</p>
</div>
</div>
</p>
`██████░░░░` 60%

Example: Style candystripe

Jinja

{{ 70 | MkProgressBar(style="candystripe") }}

Python

MkProgressBar(70, style='candystripe')

70%

[=70% "70%"]{: .candystripe}
<p>
<div class="progress progress-60plus candystripe">
<div class="progress-bar" style="width:70.00%">
<p class="progress-label">70%</p>
</div>
</div>
</p>
`███████░░░` 70%

Example: Style candystripe_animated

Jinja

{{ 80 | MkProgressBar(style="candystripe_animated") }}

Python

MkProgressBar(80, style='candystripe_animated')

80%

[=80% "80%"]{: .candystripe .candystripe-animate}
<p>
<div class="progress progress-80plus candystripe candystripe-animate">
<div class="progress-bar" style="width:80.00%">
<p class="progress-label">80%</p>
</div>
</div>
</p>
`████████░░` 80%

Bases: MkNode

__init__

__init__(
    percentage: int,
    *,
    label: str | Literal[True] | None = True,
    style: Literal["thin", "candystripe", "candystripe_animated"] | None = None,
    **kwargs: Any
) -> None

Parameters:

Name Type Description Default
percentage int

Percentage value for the progress bar

required
label str | Literal[True] | None

Label to display on top of progress bar

True
style Literal['thin', 'candystripe', 'candystripe_animated'] | None

Progress bar style

None
kwargs Any

Keyword arguments passed to parent

{}
Name Children Inherits
MkNode
mknodes.basenodes.mknode
Base class for everything which can be expressed as Markup.
graph TD
  492688635["mkprogressbar.MkProgressBar"]
  1359323199["mknode.MkNode"]
  2751680898["builtins.object"]
  1359323199 --> 492688635
  2751680898 --> 1359323199
/home/runner/work/mknodes/mknodes/src/mknodes/basenodes/mkprogressbar/metadata.toml
[metadata]
icon = "fa6-solid:bars-progress"
name = "MkProgressBar"

[[resources.css]]
filename = "progressbar.css"

[requirements.extension."pymdownx.progressbar"]

[examples.regular]
title = "Regular"
jinja = """
{{ 60 | MkProgressBar }}
"""

[examples.style_thin]
title = "Style thin"
jinja = """
{{ 60 | MkProgressBar(style="thin") }}
"""

[examples.style_candystripe]
title = "Style candystripe"
jinja = """
{{ 70 | MkProgressBar(style="candystripe") }}
"""

[examples.style_candystripe_animated]
title = "Style candystripe_animated"
jinja = """
{{ 80 | MkProgressBar(style="candystripe_animated") }}
"""

[output.markdown]
template = """
[={{ node.percentage }}% "{{ node.label }}"]
"""

[output.html5]
template = """
<label for="progress_bar">{{ node.label }}:</label>
<progress id="progress_bar" max="100" value="{{ node.percentage }}">{{ node.percentage }}%</progress>
"""
mknodes.basenodes.mkprogressbar.MkProgressBar
class MkProgressBar(mknode.MkNode):
    """Node to display a CSS-based progress bar."""

    REQUIRED_EXTENSIONS = [resources.Extension("pymdownx.progressbar")]
    ICON = "fontawesome/solid/bars-progress"
    CSS = [resources.CSSFile("progressbar.css")]
    ATTR_LIST_SEPARATOR = ""

    def __init__(
        self,
        percentage: int,
        *,
        label: str | Literal[True] | None = True,
        style: Literal["thin", "candystripe", "candystripe_animated"] | None = None,
        **kwargs: Any,
    ) -> None:
        """Constructor.

        Args:
            percentage: Percentage value for the progress bar
            label: Label to display on top of progress bar
            style: Progress bar style
            kwargs: Keyword arguments passed to parent
        """
        super().__init__(**kwargs)
        self._label = label
        self.percentage = percentage
        self.style = style
        match self.style:
            case "thin":
                self.add_css_class("thin")
            case "candystripe":
                self.add_css_class("candystripe")
            case "candystripe_animated":
                self.add_css_class("candystripe")
                self.add_css_class("candystripe-animate")
            case None:
                pass

    @property
    def label(self) -> str:
        match self._label:
            case str():
                return self._label.format(percentage=self.percentage)
            case True:
                return f"{self.percentage}%"
            case _:
                return ""

    def to_md_unprocessed(self) -> str:
        return rf'[={self.percentage}% "{self.label}"]'
Page info
Code for this page
mknodes.manual.nodes_section.create_section_for_nodes
def create_section_for_nodes(
    nav: mk.MkNav,
    klasses: Sequence[type[mk.MkNode]],
) -> mk.MkTable:
    table = mk.MkTable(columns=["Node", "Docstrings", "Markdown extensions"])
    for kls in klasses:
        tpl = "classpage_custom.jinja"
        page = mk.MkClassPage(kls, icon=kls.ICON, template_path=tpl, parent=nav, hide="toc")
        nav += page
        if kls.STATUS:
            page.metadata.status = kls.STATUS
        elif kls.JS_FILES:
            page.metadata.status = "js"
        elif kls.CSS:
            page.metadata.status = "css"
        page.created_by = create_section_for_nodes
        link = mk.MkLink(page, kls.__name__, icon=kls.ICON)
        extensions = ", ".join(f"`{i}`" for i in kls.REQUIRED_EXTENSIONS)
        table.add_row((link, kls.__doc__, extensions))
    return table
Resources
Resources(css=[],
          markdown_extensions={'admonition': {},
                               'pymdownx.details': {},
                               'pymdownx.highlight': {'anchor_linenums': True,
                                                      'line_spans': '__span',
                                                      'pygments_lang_class': True},
                               'pymdownx.progressbar': {},
                               'pymdownx.superfences': {'custom_fences': [{'class': 'mermaid',
                                                                           'format': <function fence_code_format at 0x785e0f644250>,
                                                                           'name': 'mermaid'}]},
                               'pymdownx.tabbed': {},
                               'tables': {}},
          plugins=[Plugin('mkdocstrings')],
          js=[],
          assets=[Asset('progressbar_4cf9771.css')],
          packages=[])
Metadata
created:
  source_filename: /home/runner/work/mknodes/mknodes/src/mknodes/manual/nodes_section.py
  source_function: create_section_for_nodes
  source_line_no: 93
hide:
- toc
icon: fontawesome/solid/bars-progress
status: css
title: MkProgressBar